package com.gexiaobao.pigeon.ui.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.model.bean.PigeonBean

/**
 * created by : hxw
 * @date : 20221129
 * Describe :
 */
class MyPigeonAdapter(data: ArrayList<PigeonBean.RingInfo>) :
    BaseQuickAdapter<PigeonBean.RingInfo, BaseViewHolder>(R.layout.item_pigeon_list, data) {

    override fun convert(holder: BaseViewHolder, item: PigeonBean.RingInfo) {
        holder.setText(R.id.tv_item_pigeon_nickname, item.pigeonName.ifEmpty { context.getString(R.string.No_nickname_yet) })
        holder.setText(R.id.tv_item_pigeon_zh_code, item.ringId)
        holder.setText(R.id.tv_item_pigeon_sex, getPigeonSex(item.sex))
        holder.setText(R.id.tv_item_pigeon_eye_color, getEyePattern(item.eyePattern))
        holder.setVisible(R.id.tv_item_pigeon_state, false)//1、训放  2、比赛  3、正常（3种状态）

        if (item.ringType == 2 && item.pairOwner == 2) {
            holder.setVisible(R.id.tv_item_pigeon_delete, false)
        } else {
            holder.setVisible(R.id.tv_item_pigeon_delete, true)
        }

        holder.setText(R.id.tv_item_pigeon_color, item.featherColorStr)
        if (item.featherColorStr == "未知") {
            holder.setBackgroundResource(R.id.tv_item_pigeon_color, R.drawable.round_pigeon_unknown_bg15)
        } else {
            holder.setBackgroundResource(R.id.tv_item_pigeon_color, R.drawable.round_pigeon_color_bg15)
        }

        when (item.sex) {
            2 -> {
                holder.setBackgroundResource(R.id.tv_item_pigeon_sex, R.drawable.round_pigeon_sex_ci_color_bg15)
            }

            3 -> {
                holder.setBackgroundResource(R.id.tv_item_pigeon_sex, R.drawable.round_pigeon_sex_xiong_color_bg15)
            }

            else -> {
                holder.setBackgroundResource(R.id.tv_item_pigeon_sex, R.drawable.round_pigeon_unknown_bg15)
            }
        }
        when (item.eyePattern) {
            2, 3, 4 -> {
                holder.setBackgroundResource(R.id.tv_item_pigeon_eye_color, R.drawable.round_pigeon_eye_color_bg15)
            }

            else -> {
                holder.setBackgroundResource(R.id.tv_item_pigeon_eye_color, R.drawable.round_pigeon_unknown_bg15)
            }
        }

        when (item.ringType) {
            1 -> holder.setVisible(R.id.tv_item_pigeon_type, false)
            2 -> holder.setVisible(R.id.tv_item_pigeon_type, true)
        }
    }

    private fun getEyePattern(eye: Int): String {
        return when (eye) {
            2 -> {
                context.getString(R.string.pigeon_yellow)//"黄"
            }

            3 -> {
                context.getString(R.string.pigeon_sha)//"砂"
            }

            4 -> {
                context.getString(R.string.pigeon_bull)//"牛"
            }

            else -> {
                context.getString(R.string.unkown)//"未知"
            }
        }
    }

    private fun getPigeonSex(sex: Int): String {
        return when (sex) {
            2 -> {
                context.getString(R.string.hint_female)//"雌"
            }

            3 -> {
                context.getString(R.string.hint_male)//"雄"
            }

            else -> {
                context.getString(R.string.unkown)//"未知"
            }
        }
    }
}